
object ScalaExtends {

    def main(args: Array[String]): Unit = {
        var subClass: SubClass = new SubClass()
        println(subClass.constant, subClass.variable)
        subClass.method()

        // isInstanceOf & asInstanceOf
        var flag: Boolean = subClass.isInstanceOf[BaseClass]
        println(flag)
        if (flag) {
            var baseClass: BaseClass = subClass.asInstanceOf[BaseClass]
            println(baseClass.constant)
        }

        // getClass & classOf
        flag = subClass.getClass == classOf[BaseClass]
        println(flag)

    }


    class BaseClass() {
        val constant: String = "constant"
        var variable: String = "variable"

        def method(): Unit = {
            println("BaseClass", variable)
        }
    }

    // 单继承
    class SubClass extends BaseClass() {
        // 注意override只能重写val常量
        override val constant: String = "override"

        override def method() = {
            // super调用基类方法，不能调用基类成员
            super.method()
            println("SubClass", constant)
        }

    }

    // 特征：
    trait Trait {

    }

    trait ExtendsTrait extends Trait {

    }

    trait ClassTrait extends Class {

    }

    trait BaseTrait {

    }

    // 多继承
    class SubTrait extends BaseTrait with Trait {

    }


}
